package ramakrishnanmoreHealthView;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.util.HashMap;
import javax.swing.*;

import ramakrishnanmoreHealthControl.StudentFormListBoxListener;
import ramakrishnanmoreHealthControl.StudentFormOkActionListener;
import ramakrishnanmoreHealthControl.StudentFormRadioButtonListener;
import ramakrishnanmoreHealthControl.StudentFormTextBoxListener;
import ramakrishnanmoreHealthModel.Student.Student.Disease;



//Draws and fires events for the Student Form.
public class StudentInformationForm extends JFrame
	{

		private static final long	serialVersionUID	= 6226813554019434874L;

		//Stores Information of Component-Value pair that is the component type and the Data it stores.
		public static HashMap<String, Object> studentInfoFormIp = new HashMap<String, Object>();
		
		//Disease Label and List Box.
		static JLabel jblDisease;
		public static JList diseaselist; 
		
		static JLabel jblStudentInfo;
		
		//Student Name text field
		static JTextField jtxtFirstName;
		static JTextField jtxtLastName ;
		
		//That DOB Radio Button and YEAR text field.
		static JLabel jblMonths;
		static JLabel jblYear ;
		static JLabel jblDOB ;
	    static JTextField jtxtDOBYear;
		static JRadioButtonMenuItem janDOB ;
		static JRadioButtonMenuItem febDOB;
		static JRadioButtonMenuItem marDOB;
		static JRadioButtonMenuItem aprDOB ;
		static JRadioButtonMenuItem mayDOB ;
		static JRadioButtonMenuItem junDOB ;
		static JRadioButtonMenuItem julDOB ;
		static JRadioButtonMenuItem augDOB ;
		static JRadioButtonMenuItem sepDOB ;
		static JRadioButtonMenuItem octDOB; 
		static JRadioButtonMenuItem novDOB; 
		static JRadioButtonMenuItem decDOB; 
	    public static ButtonGroup bgroup;
	    
	    //Student Age, weight and height text fields.
		static JTextField jtxtAge;
		static JTextField jtxtWeight;
		static JTextField jtxtHeight;
		
		public static  JButton jbtOK;

		
		
		//CONSTRUCTORS ======================================
		//INTENT: Adds the components to the frame and fires events when data is entered in those components.
		//PRE-CONDITION : 
			//1. Always Press the "Enter" Button with the caret in the text field to fire the text field event.
			//2. Select at least one List Item from the List Box.
			//3. Age has to be Integers and less than 41
			//4. 20<=Weight<=400 and should be Int's
			//5. 1<=Height<=7 and should be Int's
		//POST-CONDITION: 
			//1. Sends the user input data to calculate the Seriousness factor of the Student. 
		public StudentInformationForm()
			{
		    
			    setLayout(null);
			    
			    // Add a button into the frame
			    jbtOK = new JButton("OK");
			    add(jbtOK);
			    
			    jblStudentInfo = new JLabel("Please Enter your personal Health information: ");
			    add(jblStudentInfo);
			    
			    //JFormattedTextField  jtxtFirstName = new JFormattedTextField("FirstName");
			    //jtxtFirstName.setColumns(4);
			    //first Name
			    jtxtFirstName = new JTextField("First Name", 8);
			    add(jtxtFirstName);

			    //last name 
			    jtxtLastName = new JTextField("Last Name", 8);
			    add(jtxtLastName);
			    
			    //age<100
			    jtxtAge = new JTextField("Age",2);
			    add(jtxtAge);
			    
			    //weight
			    jtxtWeight = new JTextField("Weight",3);
			    add(jtxtWeight);
			    
			    //height
			    jtxtHeight = new JTextField("Height",1);
			    add(jtxtHeight);
			    
			    //disease
			    jblDisease = new JLabel("Diseases: ");
			    jblDisease.setMinimumSize(new Dimension(15,10));
			    add(jblDisease);
			    
			    //All the Disease the Student can choose from. 
			    //Student can choose only Diseases from the list. 
			    Disease[] diseaseArrayList = Disease.values();
			    diseaselist = new JList(diseaseArrayList);
			    diseaselist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			    diseaselist.setSelectedIndex(0);
			    add(diseaselist);
			    
			    
			    
			    
			    jblDOB = new JLabel("Date of Birth");
			    add(jblDOB);
			    
			    //Panel consists of the DOB Year text field and a sub panel DOBMonths radioButtonPanel.
			    JPanel dobPanel = new JPanel();
			    dobPanel.setLayout(null);
			    dobPanel.setBorder(BorderFactory.createLineBorder(Color.black));
			    
			    jblMonths = new JLabel("Month");
			    dobPanel.add(jblMonths);
			    
			    jblYear = new JLabel("Year");
			    dobPanel.add(jblYear);
			    
			    jtxtDOBYear = new JTextField("Year", 4);
			    dobPanel.add(jtxtDOBYear);
			    
			    add(dobPanel);
			    
			    
			    
			    //The sub-panel to the DOBPanel which has Months Name.
			    JPanel dobmonthPanel = new JPanel(new GridLayout(12,2));
			    dobmonthPanel.setBorder(BorderFactory.createLineBorder(Color.black));

			    janDOB = new JRadioButtonMenuItem("Jan");
			    febDOB = new JRadioButtonMenuItem("Feb");
			    marDOB = new JRadioButtonMenuItem("Mar");
			    aprDOB = new JRadioButtonMenuItem("Apr");
			    mayDOB = new JRadioButtonMenuItem("May");
			    junDOB = new JRadioButtonMenuItem("Jun");
			    julDOB = new JRadioButtonMenuItem("Jul");
			    augDOB = new JRadioButtonMenuItem("Aug");
			    sepDOB = new JRadioButtonMenuItem("Sept");
			    octDOB = new JRadioButtonMenuItem("Oct");
			    novDOB = new JRadioButtonMenuItem("Nov");
			    decDOB = new JRadioButtonMenuItem("Dec");
			    
			    bgroup = new ButtonGroup();
			    bgroup.add(janDOB);
			    bgroup.add(febDOB);
			    bgroup.add(marDOB);
			    bgroup.add(aprDOB);
			    bgroup.add(mayDOB);
			    bgroup.add(junDOB);
			    bgroup.add(julDOB);
			    bgroup.add(augDOB);
			    bgroup.add(sepDOB);
			    bgroup.add(octDOB);
			    bgroup.add(novDOB);
			    bgroup.add(decDOB);
  
			    dobmonthPanel.add(janDOB);
			    dobmonthPanel.add(febDOB);
			    dobmonthPanel.add(marDOB);
			    dobmonthPanel.add(aprDOB);
			    dobmonthPanel.add(mayDOB);
			    dobmonthPanel.add(junDOB);
			    dobmonthPanel.add(julDOB);
			    dobmonthPanel.add(augDOB);
			    dobmonthPanel.add(sepDOB);
			    dobmonthPanel.add(octDOB);
			    dobmonthPanel.add(novDOB);
			    dobmonthPanel.add(decDOB);
			    
			    dobPanel.add(dobmonthPanel);
			  
			    			    
			    //Sets the dimension and orientation of all the Components.
			    Insets insets = getInsets();
			    
			    Dimension size = jblStudentInfo.getPreferredSize();
			    jblStudentInfo.setBounds(10 + insets.left, 10 + insets.top, 76 + size.width, 5 + size.height);
			    
			    size = jtxtFirstName.getPreferredSize();
				jtxtFirstName.setBounds(10 + insets.left, 44 + insets.top,76 + size.width, 5 + size.height);
				
				size = jtxtLastName.getPreferredSize();
			    jtxtLastName.setBounds(250 + insets.left, 44 + insets.top, 76 + size.width, 5 + size.height);
			    
			    size = jtxtAge.getPreferredSize();
			    jtxtAge.setBounds(450 + insets.left, 44 + insets.top, 14 + size.width, 5 + size.height);
			    
			    size = jtxtWeight.getPreferredSize();
			    jtxtWeight.setBounds(600 + insets.left, 44 + insets.top, 20 + size.width, 5 + size.height);
			    
			    size = jtxtHeight.getPreferredSize();
			    jtxtHeight.setBounds(600 + insets.left, 106 + insets.top, 20 + size.width, 5 + size.height);
			    
			    size = jblDisease.getPreferredSize();
			    jblDisease.setBounds(450 + insets.left, 80 + insets.top, 76 + size.width, 5 + size.height);
			    
			    size= diseaselist.getPreferredSize();
			    diseaselist.setBounds(450 + insets.left, 150 + insets.top, 116 + size.width, 0 + size.height);
			    		    
			    size = jblDOB.getPreferredSize();
			    jblDOB.setBounds(10 + insets.left, 85 + insets.top, 127 + size.width, 10 + size.height);
			    
			    size = dobPanel.getPreferredSize();
			    dobPanel.setBounds(10 + insets.left, 106+ insets.top, 420 + size.width, 440 + size.height);
			    
			    size = jblMonths.getPreferredSize();
			    jblMonths.setBounds(10 + insets.left, 10+ insets.top, 152 + size.width, 10 + size.height);
			    
			    size = jblYear.getPreferredSize();
			    jblYear.setBounds(200 + insets.left, 10+ insets.top, 152 + size.width, 10 + size.height);
			    
			    size = jtxtDOBYear.getPreferredSize();
			    jtxtDOBYear.setBounds(200 + insets.left, 30+ insets.top, 97 + size.width, 5 + size.height);
			    
			    size = dobmonthPanel.getPreferredSize();
			    dobmonthPanel.setBounds(10 + insets.left, 30+ insets.top, 100 + size.width, 150+ size.height);

 				size = jbtOK.getPreferredSize();
			    jbtOK.setBounds(650 + insets.left, 390 + insets.top, 40+  size.width , size.height + 15);
			    
			    
			    
			    //Fires Events when data is selected or entered in the Form. 
			    //NOTE: After entering data press the Enter button to fire the individual events. 
			    jtxtFirstName.addActionListener(new StudentFormTextBoxListener("firstName"));
			    jtxtLastName.addActionListener(new StudentFormTextBoxListener("lastName"));
			    //jtxtAge.addActionListener(new StudentFormTextBoxListener("age"));
			    jtxtWeight.addActionListener(new StudentFormTextBoxListener("weight"));
			    jtxtHeight.addActionListener(new StudentFormTextBoxListener("height"));
			    diseaselist.addListSelectionListener(new StudentFormListBoxListener("disease"));
			    
			    janDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    febDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    marDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    aprDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    mayDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    junDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    julDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    augDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    sepDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    octDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    novDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    decDOB.addActionListener(new StudentFormRadioButtonListener("dobmonth"));
			    
			    jtxtDOBYear.addActionListener(new StudentFormTextBoxListener("dobyear"));
			    
			    
			    //The button Will use data entered on the form to calculate the Seriousness factor of the Student. 
			    jbtOK.addActionListener(new StudentFormOkActionListener (studentInfoFormIp));
			   
			}

		
		//INTENT: Creates the frame and adds the the Components in it. 
		//PRE-CONDITION :none 
		//POST-CONDITION:none
		public static void drawStudentInfoForm() {
			    
			    StudentInformationForm frame = new StudentInformationForm();
			    //frame.pack();
			    frame.setSize(800, 650); // Set the frame size
			    frame.setLocationRelativeTo(null); // New since JDK 1.4
			    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			    frame.setVisible(true); // Display the frame
			    
			  }	
		
		
		public enum MonthCode

		{
		Jan(1),
		Feb(2),
		Mar(3),
		Apr(4),
		May(5),
		Jun(6),
		Jul(7),
		Aug(8),
		Sep(9),
		Oct(10),
		Nov(11),
		Dec(12),
		Invalid(999);
		
		private final int monthCodex_;
		
		MonthCode(int MonthCode)
			{
				this.monthCodex_= MonthCode;
			}

		public int GetMonthCode()
			{
				return monthCodex_;
			}
		}
		
		
	}
